<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
</html>
<script>
     var arr=[5,3,7,1,2,8];
     for(var i=0;i<arr.length-1;i++){
         var min = arr[i]
         var a = i
         for(var j=i+1;j<arr.length-1;j++){
             if(arr[j]<min){
                 min=arr[j]
                 a=j
             }
         }
         var t=arr[i]
         arr[i]=arr[a]
         arr[a]=t
     }
     console.log(arr);
     
</script>